﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;
namespace Fang.Common.Math
{
    public class Formula
    {
        /// <summary>
        /// paras/value的个数一定要相等
        /// </summary>
        /// <param name="paras"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static decimal ReturnFormulaResult(string Formula)
        {
            if (string.IsNullOrEmpty(Formula))
            {
                return 0.0m;
            }
            try
            {
                Microsoft.JScript.Vsa.VsaEngine eng = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                object objresult = Microsoft.JScript.Eval.JScriptEvaluate(Formula, eng);
                return System.Convert.ToDecimal(objresult);
            }
            catch { return 0.0m; }

        }
    }
}
